package com.test19.lock;

import java.util.concurrent.locks.ReentrantLock;

public class LockDemo {
	private static ReentrantLock reentrantLock = new ReentrantLock();

	public static void fight() {
		reentrantLock.lock();
		
		//检验当出现异常，没有释放锁，出现的情况
//		System.out.println(1 / 0);
		System.out.println(Thread.currentThread().getName());
		
		
		reentrantLock.unlock();
	}

	public static void main(String[] args) {
		Runnable runnable = new Runnable() {

			@Override
			public void run() {
				LockDemo.fight();
			}
		};
		Thread t1 = new Thread(runnable);
		t1.setName("t1");
		t1.start();

		Thread t2 = new Thread(runnable);
		t2.setName("t2");
		t2.start();

		Thread t3 = new Thread(runnable);
		t3.setName("t3");
		t3.start();

		Thread t4 = new Thread(runnable);
		t4.setName("t4");
		t4.start();
	}
}
